/*
 * @Author: your name
 * @Date: 2021-10-25 09:55:16
 * @LastEditTime: 2021-10-28 10:31:41
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \vue_admin\src\utils\toolFunction.ts
 */
// 解析url地址
export const parseUrl = (url:string)=> {
  const obj = {}
  const arr = url.substr(url.indexOf('?') + 1).split('&')
  arr.forEach(function (item) {
    const tmp = item.split('=')
    obj[tmp[0]] = tmp[1]
  })
  return obj
}

// 过滤挑选数据
export const pick = (obj, value)=> {
  const result = {}
  const fields = Array.isArray(value) ? value : [value]
  const keys = Reflect.ownKeys(obj)
  for (let i = 0; i < keys.length; i++) {
    const key = keys[i]
    if (!value || fields.includes(key)) {
      result[key] = obj[key]
    }
  }
  return result
}

// 通过id获取name
export const getName = (id:any, array:any)=> {
  return array.find((item:any)=>{
    return item.value === id;
  })?.label || id;
}